<template>
	<view class="index">
		<MusicHead title="网易云音乐" :isShowIcon="false"></MusicHead>
		<view class="container">
			<scroll-view scroll-y="true">
				<view class="index-search" @tap="handleToSearch">
					<text class="iconfont iconsearch"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<view v-if="loading">
					<m-for-skeleton
						:avatarSize="200"
						:row="3"
						:loading="loading"
						isarc="square"
						v-for="(item,key) in 10"
						:key="key"
						:titleStyle="{}"
						:title="false"
					>
					</m-for-skeleton>
				</view>
				<view v-else class="index-list">
					<view 
						v-for="item in topList"
						:key="item.id"
						class="index-list-item"
						@tap="handleToList(item.id)"
					>
						<view class="index-list-item-img">
							<image :src="item.coverImgUrl" mode=""></image>
							<text>{{ item.updateFrequency }}</text>
						</view>
						<view class="index-list-item-text">
							<view 
								v-for="item, index in item.tracks" :key="index"
							>
							{{ index + 1 }}.{{ item.first }} - {{ item.second }}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import { topList } from "@/common/api.js"
	import MusicHead from "@/components/MusicHead.vue"
	import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton"
	
	export default {
		data() {
			return {
				title: 'Hello',
				topList: [],
				loading: true
			}
		},
		components: {
			MusicHead,
			mForSkeleton
		},
		onLoad() {
			this.getData();
		},
		methods: {
			async getData() {
				const res = await topList()
				this.topList = res
				this.loading = false
			},
			handleToSearch() {
				uni.navigateTo({
					url: "/pages/search/search"
				})
			},
			handleToList(id) {
				uni.navigateTo({
					url: "/pages/list/list?id=" + id
				})
			}
		}
	}
</script>

<style scoped>
	.index {
		
	}
	.index-search {
		display: flex;
		align-items: center;
		height: 160rpx;
		margin: 24rpx 30rpx 30rpx;
		height: 80rpx;
		border-radius: 50rpx;
		background-color: #f7f7f7;
	}
	.index-search text {
		font-size: 26rpx;
		margin: 0 26rpx;
	}
	.index-search input {
		font-size: 28rpx;
		flex: 1;
	}
	
	.index-list {
		margin: 0 30rpx;
	}
	.index-list-item {
		display: flex; 
		margin-bottom: 34rpx;
		position: relative;
	}
	.index-list-item-img {
		width: 212rpx;
		height: 212rpx;
		border-radius: 32rpx;
		overflow: hidden;
		margin-right: 22rpx;
	}
	.index-list-item-img image {
		width: 100%;
		height: 100%;
	}
	.index-list-item-img text {
		position: absolute;
		left: 12rpx;
		bottom: 16rpx;
		color: white;
		font-size: 20rpx;
	}
	.index-list-item-text {
		font-size: 24rpx;
		line-height: 66rpx;
	}
</style>
